<script lang="ts">
export default {
  name: "MyCart",
  beforeRouteEnter(to,from,next){
    if(!localStorage.getItem('loginInfo')){
      next({
        path:'/login',
        query:{
          returnUrl:to.fullPath
        }
      })
    }else {
      next();
    }
  },
}
</script>

<template>
<div>
  <h3>我的购物车</h3>
  <ul v-for="item in $store.state.myCartGoods" :key="item.id">
    <li>商品名称 :  {{item.productName}}</li>
    <li>商品单价 :  {{item.productPrice}}</li>
    <li>商品数量 :  <button @click="$store.commit('REDUCE_NUM',item)">-</button> {{item.num}} <button @click="$store.commit('ADD_TO_MY_CART',item)">+</button></li>
    <hr/>
  </ul>
  <h3>总计 : {{$store.getters.total}}</h3>
</div>
</template>

<style scoped>

</style>
